package com.sztz.mapstruct.E入参转换;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.Map;

/**
 * CarMapper
 *
 * @author yyf
 * @email yeyafei@hotmail.com
 */
@Mapper
public interface CarMapper {

    CarMapper INSTANCE = Mappers.getMapper(CarMapper.class);

    /**
     * parameter属性相同会直接拷贝进target 无需@Mapping
     *
     * @param name
     * @return CarDto
     */
    CarDTO toDto(String name);

    /**
     * parameter属性不相同需@Mapping
     *
     * @param carName
     * @param age
     * @param owner
     * @return CarDto
     */
    @Mappings({
            @Mapping(source = "carName", target = "name"),
            @Mapping(source = "age", target = "owner.age"),
            @Mapping(source = "owner", target = "owner.name")
    })
    CarDTO toDto2(String carName, String age, String owner);


    /**
     * map 入参
     *
     * @param map
     * @return CarDTO
     */
    @Mappings({
            @Mapping(source = "ownerAge", target = "owner.age"),
            @Mapping(source = "ownerName", target = "owner.name")
    })
    CarDTO toDto3(Map<String, String> map);
}
